package algorithm.poj.p2000;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLDecoder;


/**
 * 分析：
 * 
 * 实现：
 * 
 * 经验：
 * 教训：
 * 
 * @author wong.tong@gmail.com
 *
 */
public class P2105 {

	public static void main(String[] args) throws Exception {

		InputStream input = null;
		if (false) {
			input = System.in;
		} else {
			URL url = P2105.class.getResource("P2105.txt");
			File file = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
			input = new FileInputStream(file);
		}
		
		BufferedReader stdin = new BufferedReader(new InputStreamReader(input));

		String line = stdin.readLine().trim();
		int N = Integer.valueOf(line);
		for (int i = 0;i < N; i ++) {
			line = stdin.readLine();
			String ip = "";
			ip += Integer.valueOf(line.substring(0, 8), 2) + ".";
			ip += Integer.valueOf(line.substring(8, 16), 2) + ".";
			ip += Integer.valueOf(line.substring(16, 24), 2) + ".";
			ip += Integer.valueOf(line.substring(24, 32), 2);
			System.out.println(ip);
		}
	}
}
